from django.contrib.admin import forms

import xadmin
from xadmin import views
from .models import Good, GoodImage, GoodCategory
from django import forms


class GoodAdmin(object):
    style_fields = {'detail': 'ueditor'}

    list_display = ['name', 'sold_num', 'price', 'discount', 'isDiscount', 'cost', 'integral', 'good_category', 'createdAt']

    search_fields = ('name',)

    ordering = ('-createdAt',)

    # image_thumbnail = AdminThumbnail(image_field='image_thumbnail')
    '''
    缩略图在ADMIN显示的问题暂时无法解决!
    以后用VUE处理!
    '''

    class GoodsImagesInline(object):
        model = GoodImage
        exclude = ['createdAt']
        extra = 1
        style = 'tab'

    inlines = [GoodsImagesInline]


class GoodCategoryAdmin(object):
    # goods = forms.MultipleChoiceField()
    list_display = ['name', 'p_category']


xadmin.site.register(Good, GoodAdmin)
xadmin.site.register(GoodCategory, GoodCategoryAdmin)
